package PatientManagement

import (
	"MedicalTreatment/global"
	"MedicalTreatment/model"
	"fmt"
	"github.com/gin-gonic/gin"
)

// 新建患者
func SelPat(r *gin.Engine) {
	r.POST("/selpat", func(context *gin.Context) {
		var pat model.Patient
		if err := context.ShouldBindJSON(&pat); err != nil {
			context.JSON(200, gin.H{
				"Msg": err,
			})
			return
		}
		fmt.Println("000")
		var res []model.Patient
		db := global.DB.Model(&model.Patient{})
		if pat.Patient_name != "" {
			db = db.Where("patient_name LIKE ?", pat.Patient_name+"%")
		}
		if pat.Patient_idCard != "" {
			db = db.Where("patient_id_card = ?", pat.Patient_idCard)
		}
		if err := db.Debug().Find(&res).Error; err != nil {
			context.JSON(200, gin.H{
				"Msg": err,
			})
		} else {
			context.JSON(200, gin.H{
				"Msg": res,
			})
		}
	})
}
